package com.tarena.lbs.activity.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.tarena.lbs.activity.pojo.dto.ActivityAddParam;
import com.tarena.lbs.activity.pojo.dto.ActivityUpdateParam;
import com.tarena.lbs.activity.pojo.vo.ActivityQuery;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import com.tarena.lbs.base.response.JsonResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/vv1/activity")
@Api(tags = "活动管理")
public class ActivityController {
    @Autowired
    ActivityService activityService;

    @PostMapping("/add")
    @ApiOperation(value = "添加活动", notes = "根据传入的活动信息添加新活动")
    @ApiOperationSupport(order = 10)
    public JsonResult save(@ApiParam(value = "活动添加参数对象", required = true) @RequestBody ActivityAddParam activityAddParam) {
        log.info("添加活动：{}", activityAddParam);
        activityService.addActivity(activityAddParam);
        return JsonResult.ok();
    }

    @PostMapping("/update/{id}")
    @ApiOperation(value = "修改活动", notes = "根据传入的活动 ID 和更新参数修改活动信息")
    @ApiOperationSupport(order = 20)
    public JsonResult update(@ApiParam(value = "要修改的活动 ID", required = true) @PathVariable Long id,
                             @ApiParam(value = "活动更新参数对象", required = true) @RequestBody ActivityUpdateParam activityUpdateParam) {
        log.info("修改活动：{},内容：{}",id,activityUpdateParam);
        activityService.updateActivity(id,activityUpdateParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除活动", notes = "根据传入的活动 ID 删除对应的活动")
    @ApiOperationSupport(order = 30)
    public JsonResult delete(@ApiParam(value = "要删除的活动 ID", required = true) @PathVariable Long id) {
        log.info("删除活动：{}",id);
        activityService.deleteActivity(id);
        return JsonResult.ok();
    }

    @GetMapping("/select")
    @ApiOperation(value = "查询活动", notes = "根据传入的查询参数查询活动列表")
    @ApiOperationSupport(order = 40)
    public JsonResult select(@ApiParam(value = "活动查询参数对象") ActivityQuery activityQuery) {
        log.info("查询活动：{}",activityQuery);
        List<ActivityVO> list = activityService.selectActivity(activityQuery);
        return JsonResult.ok(list);
    }
}